package com.hntest.controller;

import com.hntest.entity.Bid;
import com.hntest.entity.BidRequest;
import com.hntest.entity.Pager;
import com.hntest.service.BidRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 贷款借钱 控制类
 */
@Controller("BidRequestController")
public class BidRequestController {

    @Autowired
    private BidRequestService bidRequestService;

    public void setBidRequestService(BidRequestService bidRequestService) {
        this.bidRequestService = bidRequestService;
    }


    @RequestMapping(value = "/borrow_info",method = {RequestMethod.GET,RequestMethod.POST})
    public String select(BidRequest bidRequest, ModelMap modelMap, HttpServletRequest request){
        int id = Integer.parseInt(request.getParameter("id"));
        bidRequest.setBidrequestid(id);
        BidRequest b = bidRequestService.getUserinfo(bidRequest);
        int bidid = b.getBid().getBidid();
        String username = b.getCreateuser_id().getUsername();
        String title = b.getTitle();
        BigDecimal bidrequestAmount = b.getBidrequestamount();
        BigDecimal actualrate = b.getBid().getActualrate();
        BigDecimal availableAmount = b.getBid().getAvailableAmount();
        int returntype = b.getReturntype();
        BigDecimal currentsum = b.getCurrentsum();
        Date applytime = b.getApplytime();
        BigDecimal bidrequestamount = b.getBidrequestamount();
        int disabledays = b.getDisabledays();
        int bidcount = b.getBidcount();
        //System.out.println("------>>>"+b);

        long time = 1000*60*60*24*disabledays;//有效招标时间 毫秒
        Date deadTime = new Date(applytime.getTime()+time);

        modelMap.put("bidid",bidid);
        modelMap.put("username",username);
        modelMap.put("title",title);
        modelMap.put("bidrequestAmount",bidrequestAmount);
        modelMap.put("actualrate",actualrate);
        modelMap.put("availableAmount",availableAmount);
        modelMap.put("returntype",returntype);
        modelMap.put("needAmount",bidrequestAmount.subtract(currentsum));
        modelMap.put("deadTime",deadTime);
        modelMap.put("currentsum",currentsum);
        modelMap.put("bidrequestamount",bidrequestamount);
        modelMap.put("disabledays",disabledays);
        modelMap.put("bidcount",bidcount);
        return "borrow_info";
    }
    
}
